<template>
  <div class="login">
    <div class="login-a">
      <div class="login-img"><img src="../assets/1.jpg" alt="" /></div>
      <div class="login-biao">
        <el-form ref="form" :model="form" label-width="80px" :rules="rules">
          <el-form-item prop="username">
            <el-input
              v-model="form.username"
              prefix-icon="el-icon-user"
            ></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              v-model="form.password"
              prefix-icon="el-icon-s-goods"
              type="password"
            ></el-input>
          </el-form-item>
          <el-form-item class="a">
            <el-button type="primary" @click="onSubmit">登陆</el-button>
            <el-button>重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { loginApi } from "../utils.js/api";
export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入账号", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    onSubmit() {
      this.$refs.form.validate(async (valid) => {
        if (!valid) return false;
        const res = await loginApi(this.form);
        console.log(res);
        this.$router.push("/");
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100vh;
  background-color: rgb(243, 103, 126);
  display: flex;
  align-items: center;
  justify-content: center;
  .login-a {
    width: 600px;
    height: 400px;
    border-radius: 30px;
    background-color: #ffffff;
    position: relative;
    .login-img {
      position: absolute;
      top: -80px;
      left: 200px;
      width: 200px;
      height: 200px;
      background-color: #eee;
      border-radius: 50%;
    }
    .login-biao {
      margin-top: 150px;
    }
    .el-input {
      width: 400px;
      height: 50px;
    }
  }
}
img {
  width: 160px;
  height: 160px;
  margin-left: 20px;
  margin-top: 18px;
  border-radius: 50%;
}
.a {
  margin-left: 130px;
}
</style>